﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace Air_condition.DO
{
    [Serializable]
    class Wall : Construction
    {
        private string stypeExposure;
        private double dbheatResistance;
        private string stypeMaterial;
        private double dblength;

        public double dbLength
        {
            get { return dblength; }
            set { dblength = value; }
        }
        private double dbwidth;

        public double dbWidth
        {
            get { return dbwidth; }
            set { dbwidth = value; }
        }
        //
        public string sTypeExposure
        {
            get { return stypeExposure; }
            set { stypeExposure = value; }
        }

        private int iindex;

        public int Iindex
        {
            get { return iindex; }
            set { iindex = value; }
        }
        //
       /* public string sTypeMaterial
        {
            get { return sTypeMaterial; }
            set { stypeMaterial = value; }
        }*/

        public double DbheatResistance
        {
            get { return dbheatResistance; }
            set { dbheatResistance = value; }
        }

        //  Tính hiệu nhiệt độ dư

        public void CalculateTemperatureDiff(double dbinsideRoomTemp, double dboutsideRoomTemp)
        {
            
            // Tiếp xúc với ko khí ngoài trời
            if (stypeExposure == "N")
            {
                dbtemperatureDiff = dboutsideRoomTemp - dbinsideRoomTemp;
                dbheatTransferCoefficient = (double)1 / ((1 / 20) + dbheatResistance + (1 / 10));
            }
            else
            {
                // Tiếp xúc với ko khí của 1 ko gian ko có điều hòa
                if (stypeExposure == "T")
                {
                    dbtemperatureDiff = 0.7 * (dboutsideRoomTemp - dbinsideRoomTemp);
                    dbheatTransferCoefficient = (double)1 / ((1 / 10) + dbheatResistance + (1 / 10));
                }
                else
                {
                    dbtemperatureDiff = 0;
                }
            }
        }

        public override double CalculateConstructionHeatTransfer(double dbinsideRoomTemp, double dboutsideRoomTemp)
        {
            CalculateTemperatureDiff(dbinsideRoomTemp, dboutsideRoomTemp);
            return dbarea * dbheatTransferCoefficient * dbtemperatureDiff;
        }
        public object Clone()
        {
            object clone;
            try
            {
                using (MemoryStream stream = new MemoryStream())
                {

                    BinaryFormatter formatter = new BinaryFormatter();

                    // Serialize this object

                    formatter.Serialize(stream, this);

                    stream.Position = 0;

                    // Deserialize to another object

                    clone = formatter.Deserialize(stream);

                }
                return clone;
            }
            catch (Exception e)
            {
                return e;
            }

        }
    }
}
